package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.DmsPullTeaDataMapper;
import com.yunhai.device.service.DmsPullTeaDataService;
import com.yunhai.model.entity.dms.DmsPullTeaDataEntity;
import com.yunhai.model.vo.dms.DmsPullTeaDataQuery;
import com.yunhai.model.vo.dms.DmsPullTeaDataVo;
import org.apache.commons.beanutils.PropertyUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class DmsPullTeaDataServiceImpl implements DmsPullTeaDataService {

    @Resource
    private DmsPullTeaDataMapper dmsPullTeaDataMapper;

    /**
     * 获取 DmsPullTeaData 分页列表
     */
    @Transactional
    public IPage getDmsPullTeaDataPagination(PaginationVo paginationVo, DmsPullTeaDataQuery dmsPullTeaDataQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<DmsPullTeaDataEntity> lqs = new LambdaQueryWrapper();
        dmsPullTeaDataMapper.selectPage(page, lqs);

        List<DmsPullTeaDataEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return null;
    }


    /**
     * 获取 DmsPullTeaData 所有数据
     *
    */
    @Transactional
    public List<DmsPullTeaDataEntity> getDmsPullTeaDataAllList( DmsPullTeaDataQuery dmsPullTeaDataQuery ) throws Exception {

        LambdaQueryWrapper<DmsPullTeaDataEntity> lqs = new LambdaQueryWrapper();
        List<DmsPullTeaDataEntity> list = dmsPullTeaDataMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 DmsPullTeaData 详情
    */
    @Transactional
    public DmsPullTeaDataEntity getDmsPullTeaDataDetail( Long id) throws Exception {

        DmsPullTeaDataEntity dmsPullTeaData = dmsPullTeaDataMapper.selectById(id);
        return dmsPullTeaData;
    }

    /**
     * 新增 DmsPullTeaData
     * */
    @Transactional
    public void addDmsPullTeaData(DmsPullTeaDataVo dmsPullTeaDataVo) throws Exception {

        DmsPullTeaDataEntity dmsPullTeaData = new DmsPullTeaDataEntity();
        ReflectionCopy.copyProperties( dmsPullTeaData, dmsPullTeaDataVo );
        dmsPullTeaData.setCreateTime(new Date());
        dmsPullTeaDataMapper.insert(dmsPullTeaData);
        return;
    }


    /**
     * 更新 DmsPullTeaData
     * */
    @Transactional
    public void updateDmsPullTeaData( DmsPullTeaDataVo dmsPullTeaDataVo) throws Exception {

        if( dmsPullTeaDataVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        DmsPullTeaDataEntity dmsPullTeaData = new DmsPullTeaDataEntity();
        ReflectionCopy.copyProperties( dmsPullTeaData, dmsPullTeaDataVo );
        dmsPullTeaDataMapper.updateById(dmsPullTeaData);
        return;
    }

    /**
     * 删除 DmsPullTeaData
     * */
    @Transactional
    public void batchRemoveDmsPullTeaData( List<Long> ids ) throws Exception {


        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        dmsPullTeaDataMapper.deleteBatchIds(ids);
    }

}

      